/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * this is usd for hisense to receiver bootcomplete
 * @author libaocheng
 */
package com.hisense.settings;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;

public class HiBootCompletedReceiver extends BroadcastReceiver {


    private static final String KEY_DLNA_STATE = "dlna_state";//add for hisense DLNA
    public static final String KEY_DLNA_STATE_ON_OFF = "dlna_state_on_off";
	public static final String KEY_DLNA_STATE_ON_OFF_REAL = "dlna_state_on_off_real";
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
            //the following is add for hisense DLNA
            if (getDLNARealState(context) == 1) 
    		{
                setDLNAState(1, context);
    			context.sendBroadcast(new Intent("com.hisense.external.StartDlnaService"));
    		}
    		else 
    		{
    			setDLNAState(0, context);
    			context.sendBroadcast(new Intent("com.hisense.external.StopDlnaService"));
    		}
        }
    }
    public void setDLNAState(int state, Context mContext) {
		Settings.Secure.putInt(mContext.getContentResolver(),
                    KEY_DLNA_STATE_ON_OFF, state);
    	
    }
    public void setDLNARealState(int state, Context mContext) {
		Settings.Secure.putInt(mContext.getContentResolver(),
                    KEY_DLNA_STATE_ON_OFF_REAL, state);
    	
    }
    public int getDLNARealState(Context mContext) {
    	int enabled = 0;
		enabled = Settings.Secure.getInt(mContext.getContentResolver(),
                    KEY_DLNA_STATE_ON_OFF_REAL, 0);
    	return enabled;
    	}
}
